package be.groept.ace.cursusplanning.model.containers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import be.groept.ace.cursusplanning.model.Lector;

public class Lectoren implements Container<Lector, String> {
	
	private Map<String, Lector> lectoren;
	
	public Lectoren() {
		lectoren = new HashMap<String, Lector>();
	}

	@Override
	public void add(Lector lector) throws IllegalArgumentException{
		if(lector == null) throw new IllegalArgumentException("lector mag niet null zijn");
		if(lectoren.containsKey(lector.getLectorCode())) throw new IllegalArgumentException("lector bestaat al");
		lectoren.put(lector.getLectorCode(), lector);
	}

	@Override
	public Lector get(String lectorCode) throws IllegalArgumentException{
		if(lectorCode == null) throw new IllegalArgumentException("lector mag niet null zijn");
		if(!lectoren.containsKey(lectorCode)) throw new IllegalArgumentException("lector bestaat niet");
		return lectoren.get(lectorCode);
	}

	@Override
	public List<Lector> getAll() {
		List<Lector> lectorLijst = new ArrayList<Lector>();
		for(Iterator<String> i = lectoren.keySet().iterator(); i.hasNext();) {
			lectorLijst.add(lectoren.get(i.next()));
		}
		return lectorLijst;
	}

	@Override
	public void remove(String lectorCode) {
		if(lectorCode == null) throw new IllegalArgumentException("lector mag niet null zijn");
		if(!lectoren.containsKey(lectorCode)) throw new IllegalArgumentException("lector bestaat niet");
		lectoren.remove(lectorCode);
	}

	@Override
	public Iterator<Lector> iterator() {
		return lectoren.values().iterator();
	}

}
